import request from "@/api";
import { BaseRet, PageQuery, PageRet } from "@/api/response";

class UserRoleApi {
  /**
   * 根据用户查询角色查询
   * @param data
   * @returns
   */
  static async queryRoleByUser(data: QueryRoleByUser): Promise<PageRet<UserRoleByUser>> {
    return await request({
      url: "/sysUserRole/getRoleUserByUser",
      method: "post",
      data: data,
    });
  }

  /**
   * 保存用户角色
   * @param data
   * @returns
   */
  static async createByUser(data: UserRoleCreateByUser): Promise<BaseRet> {
    return await request({
      url: "SysUserRole/CreateByUser",
      method: "post",
      data: data,
    });
  }

  /**
   * 根据角色查询用户查询
   * @param data
   * @returns
   */
  static async queryByRole(data: QueryUserByRole): Promise<PageRet<UserRoleByRole>> {
    return await request({
      url: "/sysUserRole/Index",
      method: "post",
      data: data,
    });
  }
  /**
   * 根据角色保存用户
   * @param data
   * @returns
   */
  static async createByRole(data: UserRoleCreateByRole): Promise<BaseRet> {
    return await request({
      url: "SysUserRole/Create",
      method: "post",
      data: data,
    });
  }
}

export default UserRoleApi;

/**
 * 根据用户:查询角色参数
 */
export interface QueryRoleByUser extends PageQuery {
  userId: string;
  searchString: string;
}

/**
 * 根据用户:查询角色返回结果
 */
export interface UserRoleByUser {
  id: string;
  roleName: string;
  isCurrentUser: boolean;
}

/**
 * 根据用户:设置角色
 */
export interface UserRoleCreateByUser {
  userId: string;
  roleIdList: string[];
}

/**
 * 根据角色:查询用户参数
 */
export interface QueryUserByRole extends PageQuery {
  roleId: string;
  searchString: string;
}

/**
 * 根据角色:查询角色中的用户返回结果
 */
export interface UserRoleByRole {
  id: string;
  userName: string;
  nickName: string;
  isCurrentRole: boolean;
}

/**
 * 根据角色:设置对应用户
 */
export interface UserRoleCreateByRole {
  roleId: string;
  userIdList: string[];
}
